package com.hycreate.platform.modules.recheandrejec;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.hycreate.platform.common.config.Global;
import com.hycreate.platform.common.persistence.Page;
import com.hycreate.platform.common.utils.StringUtils;
import com.hycreate.platform.common.web.BaseController;

/**
 * 复核驳回Controller
 * @author wang
 * @version 2017-11-29
 */
@Controller
@RequestMapping(value = "${adminPath}/recheandrejec/yhcgRecheckandrejec")
public class YhcgRecheckandrejecController extends BaseController {

	@Autowired
	private YhcgRecheckandrejecService yhcgRecheckandrejecService;
	
	@ModelAttribute
	public YhcgRecheckandrejec get(@RequestParam(required=false) String id) {
		YhcgRecheckandrejec entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = yhcgRecheckandrejecService.get(id);
		}
		if (entity == null){
			entity = new YhcgRecheckandrejec();
		}
		return entity;
	}
	
	@RequiresPermissions("recheandrejec:yhcgRecheckandrejec:view")
	@RequestMapping(value = {"list", ""})
	public String list(YhcgRecheckandrejec yhcgRecheckandrejec, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<YhcgRecheckandrejec> page = yhcgRecheckandrejecService.findPage(new Page<YhcgRecheckandrejec>(request, response), yhcgRecheckandrejec); 
		model.addAttribute("page", page);
		return "modules/recheandrejec/yhcgRecheckandrejecList";
	}

	@RequiresPermissions("recheandrejec:yhcgRecheckandrejec:view")
	@RequestMapping(value = "form")
	public String form(YhcgRecheckandrejec yhcgRecheckandrejec, Model model) {
		model.addAttribute("yhcgRecheckandrejec", yhcgRecheckandrejec);
		return "modules/recheandrejec/yhcgRecheckandrejecForm";
	}

	@RequiresPermissions("recheandrejec:yhcgRecheckandrejec:edit")
	@RequestMapping(value = "save")
	public String save(YhcgRecheckandrejec yhcgRecheckandrejec, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, yhcgRecheckandrejec)){
			return form(yhcgRecheckandrejec, model);
		}
		yhcgRecheckandrejecService.save(yhcgRecheckandrejec);
		addMessage(redirectAttributes, "保存复核驳回成功");
		return "redirect:"+Global.getAdminPath()+"/recheandrejec/yhcgRecheckandrejec/?repage";
	}
	
	@RequiresPermissions("recheandrejec:yhcgRecheckandrejec:edit")
	@RequestMapping(value = "delete")
	public String delete(YhcgRecheckandrejec yhcgRecheckandrejec, RedirectAttributes redirectAttributes) {
		yhcgRecheckandrejecService.delete(yhcgRecheckandrejec);
		addMessage(redirectAttributes, "删除复核驳回成功");
		return "redirect:"+Global.getAdminPath()+"/recheandrejec/yhcgRecheckandrejec/?repage";
	}
	
	@RequestMapping(value = "listbo",method=RequestMethod.POST)
	@ResponseBody
	public List<YhcgRecheckandrejec> listbo(YhcgRecheckandrejec yhcgRecheckandrejec, HttpServletRequest request, HttpServletResponse response, Model model) {
		yhcgRecheckandrejec.setStatus("2");//查询复查驳回
		List<YhcgRecheckandrejec> page = yhcgRecheckandrejecService.findAllList(yhcgRecheckandrejec); 
		return page;
	}
	
	@RequestMapping(value = "listtong",method=RequestMethod.POST)
	@ResponseBody
	public List<YhcgRecheckandrejec> listtong(YhcgRecheckandrejec yhcgRecheckandrejec, HttpServletRequest request, HttpServletResponse response, Model model) {
		yhcgRecheckandrejec.setStatus("1");//查询复查驳回
		List<YhcgRecheckandrejec> page = yhcgRecheckandrejecService.findAllList(yhcgRecheckandrejec); 
		return page;
	}
}